//
//  LbSlider.m
//  Holyiot-DFU
//
//  Created by bill on 2021/3/24.
//

#import "LbSlider.h"

@implementation LbSlider
//左边最小值的图片
- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds;
{
//    NSLog(@"----->:%@",NSStringFromCGRect(bounds));
    CGFloat X = 0;
        CGFloat H = 21;
        CGFloat Y =( bounds.size.height - H ) *.5f;
        CGFloat W = H;
        return CGRectMake(X, Y, 0, H);
}
//右边最大值的图片
- (CGRect)maximumValueImageRectForBounds:(CGRect)bounds
{
//    NSLog(@"=====>:%@",NSStringFromCGRect(bounds));
    CGFloat H = 21;
        CGFloat Y =( bounds.size.height - H ) *.5f;
        CGFloat W = 0;
        CGFloat X = bounds.size.width - W;
        return CGRectMake(X, Y, W, H);
}

- (CGRect)trackRectForBounds:(CGRect)bounds
{
   
    CGRect minimumValueImageRect = [self minimumValueImageRectForBounds:bounds];
       CGRect maximumValueImageRect = [self maximumValueImageRectForBounds:bounds];
       CGFloat margin = 2;
       CGFloat H = 8;
       CGFloat Y =( bounds.size.height - H ) *.5f;
    //最小值图片的right加上margin
       CGFloat X = CGRectGetMaxX(minimumValueImageRect) + margin;
    //最大值图片的left减去margin再减去tack的x
       CGFloat W = CGRectGetMinX(maximumValueImageRect) - X - margin;
       return CGRectMake(X, Y, W, H);
}
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value
{
    //NSLog(@"--%@  ==%@  ~~%f",NSStringFromCGRect(bounds),NSStringFromCGRect(rect),value);
    CGFloat WH = 30;
        CGFloat margin = WH *.5f - 21 *.5f + 2;
        /// 滑块的滑动区域宽度
        CGFloat maxWidth = CGRectGetWidth(rect) + 2 * margin;
        /// 每次偏移量
        CGFloat offset = (maxWidth - WH)/(self.maximumValue - self.minimumValue);
        
        CGFloat H = WH;
        CGFloat Y = (bounds.size.height - H ) *.5f;
        CGFloat W = H;
        CGFloat X = CGRectGetMinX(rect) - margin + offset *(value-self.minimumValue);
        CGRect r =  CGRectMake(X, Y, W, H);
        return r;
}

@end
